package com.beantools.entity;

import java.lang.reflect.Method;

/**
 * 这是存储实体类的类，存储属性的名字、类型。其属性名称来源于方法，
 * 因而，需要存储方法类。方法类在后期还能用的到。
 *
 * @author baoya
 * @version 1.0
 * @since 1.1.0
 */
public class EntityStorage {

    /**
     * 当前对象的值
     */
    private Object object;

    /**
     * 当前类的类字面常量
     */
    private Class clazz;

    /**
     * 对象属性的名称
     */
    private String propertyName;

    /**
     * 对象属性的类型
     */
    private Class propertyType;

    /**
     * 对象待转为属性的方法
     */
    private Method method;

    public String getPropertyName() {
        return propertyName;
    }

    public void setPropertyName(String propertyName) {
        this.propertyName = propertyName;
    }

    public Class getPropertyType() {
        return propertyType;
    }

    public void setPropertyType(Class propertyType) {
        this.propertyType = propertyType;
    }

    public Method getMethod() {
        return method;
    }

    public void setMethod(Method method) {
        this.method = method;
    }

    public void setClazz(Class clazz) {
        this.clazz = clazz;
    }

    public Class getClazz() {
        return clazz;
    }

    public void setObject(Object object) {
        this.object = object;
    }

    public Object getObject() {
        return object;
    }

    public EntityStorage() {
    }

    public EntityStorage(String propertyName, Class propertyType, Method method) {
        this.propertyName = propertyName;
        this.propertyType = propertyType;
        this.method = method;
    }

    public EntityStorage(String propertyName, Class propertyType, Method method, Class clazz, Object object) {
        this(propertyName, propertyType, method);
        this.clazz = clazz;
        this.object = object;
    }

    @Override
    public String toString() {
        return "EntityStorage{" +
                "object=" + object +
                ", clazz=" + clazz +
                ", propertyName='" + propertyName + '\'' +
                ", propertyType=" + propertyType +
                ", method=" + method +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        EntityStorage storage = (EntityStorage) o;

        if (object != null ? !object.equals(storage.object) : storage.object != null) return false;
        if (clazz != null ? !clazz.equals(storage.clazz) : storage.clazz != null) return false;
        if (propertyName != null ? !propertyName.equals(storage.propertyName) : storage.propertyName != null)
            return false;
        if (propertyType != null ? !propertyType.equals(storage.propertyType) : storage.propertyType != null)
            return false;
        return method != null ? method.equals(storage.method) : storage.method == null;
    }

    @Override
    public int hashCode() {
        int result = object != null ? object.hashCode() : 0;
        result = 31 * result + (clazz != null ? clazz.hashCode() : 0);
        result = 31 * result + (propertyName != null ? propertyName.hashCode() : 0);
        result = 31 * result + (propertyType != null ? propertyType.hashCode() : 0);
        result = 31 * result + (method != null ? method.hashCode() : 0);
        return result;
    }

}
